import { Module } from '@nestjs/common';
import { ConfigModule, ConfigService } from '@nestjs/config';
import { AppController } from './app.controller';
import { AppService } from './app.service';
import { MqttModule } from './mqtt/mqtt.module';
import { DeviceModule } from './device/device.module';
import config from './config';
import { TypeOrmModule } from '@nestjs/typeorm';
import { RedisModule } from './redis/redis.module';
import { ScheduleModule } from '@nestjs/schedule';
import { LocalCacheModule } from './local-cache/local-cache.module';
import { MongooseModule } from '@nestjs/mongoose';

@Module({
  imports: [
    ConfigModule.forRoot({
      isGlobal : true,
      load : [config]
    }),
    TypeOrmModule.forRootAsync({
      useFactory: (configService: ConfigService) => configService.get('database'),
      inject: [ConfigService],
    }),

    MongooseModule.forRootAsync({
      useFactory: async (configService: ConfigService) => ({
        ...configService.get('mongodb.options')
      }),
      inject: [ConfigService],
    }),

    ScheduleModule.forRoot(),
    
    MqttModule,
    DeviceModule,
    RedisModule,
    LocalCacheModule
  ],
  controllers: [AppController],
  providers: [AppService],
})
export class AppModule {}
